package com.winning.vsts.merge.service.service;

import com.winning.vsts.merge.service.domain.VstsProject;
import com.winning.vsts.merge.service.jpa.VstsProjectJpaRepository;
import com.winning.vsts.merge.service.util.SpecificationBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 项目信息
 *
 * @author xcl <xcl@winning.com.cn>
 * @date 2021/11/17
 */
@Service
public class VstsProjectService {

    @Autowired
    private VstsProjectJpaRepository vstsProjectJpaRepository;


    public List<VstsProject> queryVstsProject(String projectName, String projectOwner) {
        Specification<VstsProject> specification = SpecificationBuilder.<VstsProject>builder()
            .exact("projectName", projectName)
            .exact("projectOwner", projectOwner)
            .exact("delFlag", 0)
            .exact("outpatientFlag",1).and();
        return vstsProjectJpaRepository.findAll(specification);
    }


    public VstsProject getVstsProject(Integer projectId) {
        return vstsProjectJpaRepository.findById(projectId)
            .orElseThrow(() -> new RuntimeException("未获取到对应的项目信息:" + projectId));
    }
}
